package com.restaurant.application.indexes.reservationlist.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class MiniReservationData implements PickableBean {

    public static final String FN_ID = "id";
    public static final String FN_RESERVATIONTIME = "reservationTime";
    public static final String FN_SHOPNAME = "shopName";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
             FN_ID,
             FN_RESERVATIONTIME,
             FN_SHOPNAME);

    private String id;
    private Long reservationTime;
    private String shopName;

    public MiniReservationData(String id, Long reservationTime, String shopName) {
        setId(id);
        setReservationTime(reservationTime);
        setShopName(shopName);
    }

    public MiniReservationData() {
    }

    public MiniReservationData duplicate() {
        MiniReservationData result = new MiniReservationData();
        result.id = this.id;
        result.reservationTime = this.reservationTime;
        result.shopName = this.shopName;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getId() {
        return id;
    }

    public void  setId(String value) {
        this.id = value;
    }

    public MiniReservationData withId(String value) {
        setId(value);
        return this;
    }

    public MiniReservationData withId(String value, String defaultValue) {
        setId(value == null ? defaultValue : value);
        return this;
    }

    public Long getReservationTime() {
        return reservationTime;
    }

    public void  setReservationTime(Long value) {
        this.reservationTime = value;
    }

    public MiniReservationData withReservationTime(Long value) {
        setReservationTime(value);
        return this;
    }

    public MiniReservationData withReservationTime(Long value, Long defaultValue) {
        setReservationTime(value == null ? defaultValue : value);
        return this;
    }

    public String getShopName() {
        return shopName;
    }

    public void  setShopName(String value) {
        this.shopName = value;
    }

    public MiniReservationData withShopName(String value) {
        setShopName(value);
        return this;
    }

    public MiniReservationData withShopName(String value, String defaultValue) {
        setShopName(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch(name) {
        case "id": return getId();
        case "reservationTime": return getReservationTime();
        case "shopName": return getShopName();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if(!(o instanceof MiniReservationData)) return false;
        return signature().equals(((MiniReservationData)o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean MiniReservationData has no signature defined, no hash code or equals possible.");
    }
}
